package com.google.cbmgraph;

import android.graphics.Canvas;
/**
 * This class allows fancy phones to run this efficiently by threading it
 * @author lawlerr1
 *
 */
public class GraphViewThread extends Thread {

	private GraphMap myGraph;
	public boolean run = false;
	/**
	 * Constructor 
	 * 
	 * @param map
	 */
	public GraphViewThread(GraphMap map){
		myGraph = map;
	}
	/**
	 * Run the thread, this was played with to try and minimize 
	 * blockiness. The synchronize keyword keeps retain its integrity even if parallelized.
	 */
	public void run(){
		Canvas canvas;
		while(run){
			canvas = null;
			try{
				canvas = myGraph.getHolder().lockCanvas(null);
				synchronized (myGraph.getHolder()){
					myGraph.onDraw(canvas);
				}
			}finally{
				if(canvas !=null){
					myGraph.getHolder().unlockCanvasAndPost(canvas);
				}
			}
		}
	}
}
